package cease.command.cease;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.Option;

import cease.butter.Constants;
import cease.command.HasOptionCommand;
import cease.update.Version;
import cease.urs.Session;

/**
 * @author dhf
 */
public class VersionCommand extends HasOptionCommand {

    @Option(name = "-l", usage = "query latest version", metaVar = "optional")
    private boolean showLatest;

    public String getCmdDesc() {
        return "show " + Constants.APP_NAME + " version";
    }

    private void reset() {
        showLatest = false;
    }

    public void run(Session session, String[] args) throws Exception {
        try {
            parser.parseArgument(args);
            if (showLatest) {
                Version version = Version.getLastestVersion();
                System.out.println("latest version : " + version);
            } else {
                System.out
                        .println("current version : " + Constants.APP_VERSION);
            }
        } catch (CmdLineException e) {

        } finally {
            reset();
        }
    }
}
